﻿using OpcUaHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace FPSO.HMI.Utils
{
    /// <summary>
    /// 阈值规则类
    /// </summary>
    internal class ThresholdUtil
    {
        /// <summary>
        /// 根据阈值获取舱室颜色
        /// </summary>
        /// <param name="val"></param>
        /// <param name="rule"></param>
        /// <returns></returns>
        public static SolidColorBrush GetTankFillColor(double val,Threshold rule)
        {
            if (val >= rule.BorderLeft && val < rule.Minn)
            {
                return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#0d47a1"));
            }
            else
            if (val >= rule.Minn && val < rule.Min)
            {
                return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#1e88e5"));
            }
            else
            if (val >= rule.Min && val < rule.Max)
            {
                return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#26a69a"));
            }
            else
            if (val >= rule.Max && val < rule.Maxx)
            {
                return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff9800"));
            }
            else
            if (val >= rule.Maxx && val <= rule.BorderRight)
            {
                return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#d84315"));
            }
            else
            {
                return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#0d47a1"));
            }
        }

        /// <summary>
        /// 阈值，BorderLeft和BorderRight为总范围，
        /// 例如百分比范围为0-100，
        /// 所有参数从小到大依次为BorderLeft、Minn、Min、Max、Maxx、BorderRight
        /// </summary>
        public class Threshold
        {
            /// <summary>
            /// 最小边界值
            /// </summary>
            public double BorderLeft;
            /// <summary>
            /// 最小值
            /// </summary>
            public double Min { get; set; }
            /// <summary>
            /// 极小值
            /// </summary>
            public double Minn { get; set; }
            /// <summary>
            /// 最大值
            /// </summary>
            public double Max { get; set; }
            /// <summary>
            /// 极大值
            /// </summary>
            public double Maxx { get; set; }
            /// <summary>
            /// 最大边界值
            /// </summary>
            public double BorderRight { get; set; }
        }
    }
}
